﻿<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      exclude-result-prefixes="xs"
      version="2.0">

<xsl:template match="chain_sender|r_ints" mode="cc_param">
  <tr><td>Канал</td><td><xsl:value-of select="s_cc|r_cc"/></td></tr>
  <xsl:choose>
    <xsl:when test="(s_cc_params|r_cc_params)[Fst='dbuser']">
      <tr class="important"><td>Драйвер БД</td><td><xsl:value-of 
        select="((s_cc_params|r_cc_params)[Fst='jdbcDriver'])/Snd"/></td></tr>
      <tr class="important"><td>Строка подключения</td><td><xsl:value-of 
        select="((s_cc_params|r_cc_params)[Fst='connectionURL'])/Snd"/></td></tr>
      <tr class="important"><td>Пользователь БД</td><td><xsl:value-of
      select="((s_cc_params|r_cc_params)[Fst='dbuser'])/Snd"/></td></tr>
      <!-- For sender channels only -->
      <xsl:if test="s_cc_params">
      <tr class="optional"><td>Тип сообщения (document name, namespace)</td><td><xsl:value-of
        select="s_cc_params[Fst='documentname']/Snd"/><br/><xsl:value-of
        select="s_cc_params[Fst='documentnamespace']/Snd"/></td></tr>
      <tr><td>Интервал опроса, сек</td><td><xsl:value-of
        select="s_cc_params[Fst='pollInterval']/Snd"/></td></tr>
      <tr><td>Тип обмена (QoS)</td><td><xsl:value-of select="s_cc_params[Fst='qualityOfService']/Snd"/></td></tr>
      <tr><td>Запрос выборки</td><td><xsl:value-of
        select="s_cc_params[Fst='queryStatement']/Snd"/></td></tr>
      <tr><td>Запрос обновления</td><td><xsl:value-of
        select="s_cc_params[Fst='updateStatement']/Snd"/></td></tr>
      </xsl:if>
      <!-- For receiver channels only -->
      <xsl:if test="r_cc_params">
        <tr class="optional"><td>Число одновременно обрабатываемых сообщений</td><td><xsl:value-of
          select="r_cc_params[Fst='maximumConcurrency']/Snd"/></td></tr>
        <tr><td>noOfRetries</td><td><xsl:value-of
          select="r_cc_params[Fst='noOfRetries']/Snd"/></td></tr>
        <tr><td>exactlyOnceErrorInPendingState</td><td><xsl:value-of 
          select="r_cc_params[Fst='exactlyOnceErrorInPendingState']/Snd"/></td></tr>
        <tr><td>emptyStringValue</td><td><xsl:value-of
          select="r_cc_params[Fst='emptyStringValue']/Snd"/></td></tr>
        <tr><td>batchMode</td><td><xsl:value-of
          select="r_cc_params[Fst='batchMode']/Snd"/></td></tr>
      </xsl:if>
      <tr class="optional"><td>Auto-commit</td><td><xsl:value-of
        select="((s_cc_params|r_cc_params)[Fst='autoCommit'])/Snd"/></td></tr>
      
    </xsl:when>
    <xsl:when test="(s_cc_params|r_cc_params)[Fst='file.adapterStatus']">
      <xsl:if test="(s_cc_params|r_cc_params)[Fst='ftp.host']">
        <tr class="important"><td>FTP-сервер</td><td><xsl:value-of 
          select="concat(((s_cc_params|r_cc_params)[Fst='ftp.host'])/Snd/text(), ':',
          ((s_cc_params|r_cc_params)[Fst='ftp.port'])/Snd/text())"/></td></tr>
        <tr class="important"><td>Имя пользователя FTP</td><td><xsl:value-of 
          select="((s_cc_params|r_cc_params)[Fst='ftp.user'])/Snd"/></td></tr>
        <tr class="important"><td>Каталог обмена FTP</td><td><xsl:value-of 
        select="((s_cc_params|r_cc_params)[Fst='ftp.sourceDir'])/Snd"/></td></tr>
        <tr class="important"><td>Режим обмена FTP</td><td><xsl:value-of 
          select="((s_cc_params|r_cc_params)[Fst='ftp.transferMode'])/Snd"/></td></tr>
      </xsl:if>
      <!--tr class="important"><td>Каталог обмена</td><td><xsl:value-of 
        select="((s_cc_params|r_cc_params)[Fst='jdbcDriver'])/Snd"/></td></tr>
      <tr class="important"><td>Каталог архива</td><td><xsl:value-of 
        select="((s_cc_params|r_cc_params)[Fst='connectionURL'])/Snd"/></td></tr>
      <tr class="important"><td>Каталог ошибок</td><td><xsl:value-of
      select="((s_cc_params|r_cc_params)[Fst='dbuser'])/Snd"/></td></tr>
      <tr class="important"><td>Имя файла</td><td><xsl:value-of
      select="((s_cc_params|r_cc_params)[Fst='file.sourceFileName'])/Snd"/></td></tr-->
      
      <!-- For sender channels only -->
      <xsl:if test="s_cc_params">
        <xsl:if test="s_cc_params[Fst='file.type']">
        <tr class="optional"><td>Тип сообщения (document name, namespace)</td><td><xsl:value-of
          select="s_cc_params[Fst='xml.documentName']/Snd"/><br/><xsl:value-of
            select="s_cc_params[Fst='xml.documentNamespace']/Snd"/></td></tr>
        </xsl:if>
        <tr><td>Интервал опроса, сек</td><td><xsl:value-of
        select="s_cc_params[Fst='file.pollInterval']/Snd"/></td></tr>
        <tr><td>Дисциплина обработки файла</td><td><xsl:value-of
        select="s_cc_params[Fst='ftp.processingMode']/Snd"/></td></tr>
        <xsl:if test="s_cc_params[Fst='ftp.processingMode']/Snd='archive'">
          <tr><td>Архивировать на FTP:</td><td><xsl:value-of
            select="s_cc_params[Fst='ftp.archiveOnFtpServer']/Snd"/></td></tr>
        </xsl:if>
        file.archiveDir
        file.archiveWithTimestamp
        file.encoding
        errorArchiveWithTimestamp
        errorArchiveDir
        enableDynConfigSender
        emptyFileHandling
        dynConfigSourceFileTimestamp
        dynConfigSourceFileSize
        dynConfigSourceFTPHost
        dynConfigFileType
        dynConfigFileName
        dynConfigFileEncoding
        dynConfigDirectory
        advancedSourceFileSelection
        ftp.connection
        ftp.dataConnectionMode
        ftp.security
        ftp.security.commandorder
        ftp.security.useClientCert
        xml.keyfieldType
        StrS
        xml.recordsetName
        xml.recordsetStructure
        xml.recordsetStructureOrder
        
        <tr><td>Тип обмена (QoS)</td><td><xsl:value-of select="s_cc_params[Fst='file.qualityOfService']/Snd"/></td></tr>
        <tr><td>Имя очереди</td><td><xsl:value-of select="s_cc_params[Fst='file.queueName']/Snd"/></td></tr>
      </xsl:if>

      <!-- For receiver channels only -->
      <xsl:if test="r_cc_params">
        createTargetDirectory
        dynConfigDirectory
        dynConfigFailOnMissingProperties
        dynConfigFileEncoding
        dynConfigFileName
        dynConfigFileType
        dynConfigTargetTempFileName
        emptyMessageHandling
        enableDynConfigReceiver
        file.adapterStatus
        file.advanced
        file.executeTerminateAfterTimeout
        file.preprocess.executeTerminateAfterTimeout
        file.targetFileName
        file.type
        file.varSubstitution
        file.varSubstitutionDisableSecurity
        ftp.anonymous
        ftp.connection
        ftp.dataConnectionMode
        ftp.overwrite
        ftp.putSafe
        ftp.security.commandorder
        ftp.security.useClientCert
        ftp.transferMode
        ftp.writeMode
        maximumConcurrency
        
        
        <tr class="optional"><td>Число одновременно обрабатываемых сообщений</td><td><xsl:value-of
          select="r_cc_params[Fst='maximumConcurrency']/Snd"/></td></tr>
        <tr><td>noOfRetries</td><td><xsl:value-of
          select="r_cc_params[Fst='noOfRetries']/Snd"/></td></tr>
        <tr><td>exactlyOnceErrorInPendingState</td><td><xsl:value-of 
          select="r_cc_params[Fst='exactlyOnceErrorInPendingState']/Snd"/></td></tr>
        <tr><td>emptyStringValue</td><td><xsl:value-of
          select="r_cc_params[Fst='emptyStringValue']/Snd"/></td></tr>
        <tr><td>batchMode</td><td><xsl:value-of
          select="r_cc_params[Fst='batchMode']/Snd"/></td></tr>
      </xsl:if>
      <tr class="optional"><td>Auto-commit</td><td><xsl:value-of
        select="((s_cc_params|r_cc_params)[Fst='autoCommit'])/Snd"/></td></tr>
      
    </xsl:when>
  </xsl:choose>
  
</xsl:template>

<xsl:template match="Scenario">
  <hr/><h3>#TODO TITLE# <xsl:value-of select="scenario_name"/></h3>
  <p>#TODO DESCRIPTION# <xsl:value-of select="scenario_description"/></p>

  <xsl:for-each
    select="scenario_chains/chain_sender">
    <h4>Исходящий интерфейс для системы (#TODO TEXT# <xsl:value-of select="s_sys/system"/>)</h4>
  <table border="1px" cellpadding="0px" cellspacing="0px">
    <thead title="123">
      <tr><td>Признак</td><td>Значение</td></tr>
    </thead>
    <tbody>
      <tr><td>Интерфейс</td><td><xsl:value-of select="s_int"/></td></tr>
      <!--tr><td>Сообщение</td><td>#TODO#</td></tr-->
      <tr><td>Пространство имён</td><td><xsl:value-of select="s_int"/></td></tr>
      <tr><td>Способ обмена</td><td><!--xsl:apply-templates select="'123'" mode="title"/--></td></tr>
      <tr><td colspan="2">Параметры адаптера</td></tr>
      <xsl:apply-templates select="." mode="cc_param"/>
    </tbody>
  </table>
  </xsl:for-each>
  
    <xsl:for-each
      select="scenario_chains/chain_receivers">
      <h4>Входящий интерфейс для системы <xsl:value-of select="r_sys/system"/></h4>
      <xsl:for-each select="r_ints">
      <xsl:if test="count(parent::chain_receivers/r_ints)>1"><h5>Интерфейс №<xsl:value-of
        select="position()"/></h5></xsl:if>
      <table border="1px" cellpadding="0px" cellspacing="0px">
      <thead title="123">
        <tr><td>Признак</td><td>Значение</td></tr>
      </thead>
      <tbody>
        <tr><td>Интерфейс</td><td><xsl:value-of select="r_int"/></td></tr>
        <!--tr><td>Сообщение</td><td>#TODO#</td></tr-->
        <tr><td>Пространство имён</td><td><xsl:value-of select="r_int"/></td></tr>
        <tr><td>Способ обмена</td><td><!--xsl:apply-templates select="todo" mode="title"/--></td></tr>
        <tr><td>Преобразование</td><td><xsl:value-of select="mapping"/></td></tr>
        <tr><td colspan="2">Параметры адаптера</td></tr>
        <xsl:apply-templates select="." mode="cc_param"/>
      </tbody>
      </table>
      </xsl:for-each>
      </xsl:for-each>
</xsl:template>

<xsl:template match="/root">
  <html>
    <head><title>Реестр интерфейсов</title></head>
      <body>
        <h1>Реестр интерфейсов</h1>
        <h2>Системы, участвующие в межсистемном обмене</h2>
        <h2>Интерфейсы обмена</h2>
      <xsl:apply-templates select="Scenario[scenario_name='DBF_LTRANS123']"/>  
        <xsl:apply-templates select="Scenario"/>  
      </body>
  </html>  
</xsl:template>
</xsl:stylesheet>
